﻿using System;
using System.Collections.Generic;
using Medora.DataContract;
using Medora.Model.Institutions;
using Medora.Services.Utils;

namespace Medora.Services.Institutions
{
    public class SectorsService : ServiceBase<Sector, SectorFilter>, ISectorsService
    {
        private readonly IUserService _userService;

        public SectorsService(IUow uow, IUserService userService, IFilterConstructor<SectorFilter, Sector> filterConstructor)
            : base(uow, userService, filterConstructor)
        {
            _userService = userService;
            _repository = _uow.Sectors;
        }

        public IEnumerable<Sector> GetByInstitutionByUserId(Guid userId)
        {
            var user = _userService.GetById(userId);
            if (user != null && user.InstitutionId.HasValue)
            {
                return _repository.Get(o => o.InstitutionId == user.InstitutionId);
            }
            return new List<Sector>();
        }
    }
}